package cmd

import (
	"errors"
	"fmt"

	"github.com/spf13/cobra"
)

var printFlag string

func PrintCmd() *cobra.Command {
	var printCmd = &cobra.Command{
		Use:   "print [OPTIONS] [COMMANDS]",
		Short: "Print the those message",
		Long:  `Print the special message`,
		Run: func(cmd *cobra.Command, args []string) {
			fmt.Println("run print...")
			fmt.Printf("printFlag: %v\n", printFlag)
			// 使用rootCmd中的参数 需要在rootCmd开启 TraverseChildren: true,
			fmt.Printf("Source: %v\n", Source)
		},
		Args: func(cmd *cobra.Command, args []string) error {
			if len(args) < 1 {
				return errors.New("requires at least one arg")
			}
			if args[0] != "a" {
				return errors.New("first argument must be 'a'")
			}
			return nil
		},
	}

	printCmd.Flags().StringVarP(&printFlag, "flag", "f", "", "print flag for local")

	return printCmd
}
